home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
edit
/
dte5_1.zip
/
BLOCK.C
next >
Wrap
C/C++ Source or Header
|
1991-02-06
|
39KB
|
1,231 lines
/*
* Written by Douglas Thomson (1989/1990)
*
* This source code is released into the public domain.
*/
/*
* Name: dte - Doug's Text Editor program - block commands module
* Purpose: This file contains all the commands than manipulate blocks.
* File: block.c
* Author: Douglas Thomson
* System: this file is intended to be system-independent
* Date: October 1, 1989
*/
#ifdef HPXL
#include "commonh"
#include "utilsh"
#include "blockh"
#else
#include "common.h"
#include "utils.h"
#include "block.h"
#endif
/*
* prototypes for all functions in this file
*/
void set_marker ARGS((windows *window, int n));
void mark_start ARGS((windows *window));
void mark_end ARGS((windows *window));
void prepare_block ARGS((windows *window));
void block_move ARGS((windows *window));
void block_copy ARGS((windows *window));
void block_read ARGS((windows *window, int fixup));
int check_block ARGS((windows *window));
void block_delete ARGS((windows *window));
void block_indent ARGS((windows *window));
void block_unindent ARGS((windows *window));
void block_write ARGS((windows *window));
void block_print ARGS((windows *window));
/*
* Name: set_marker
* Purpose: To record the position of a marker in the file.
* Date: October 1, 1989
* Passed: window: information required to access current window
* n: the number of the marker to set
* Notes: n must be in the range 0..9
*/
void set_marker(window, n)
windows *window;
int n;
{
int col; /* cursor column, or end of line, whichever is less */
int len; /* length of current line */
if (g_status.copied) {
/*
* current line buffer is active, so set the buffer marker
*/
if ((col = window->ccol) > (len = linelen(g_status.line_buff))) {
/*
* markers can only be placed where there is actually some
* text. If the cursor is beyond the end of the line, then
* the marker must be set at the end of the line
*/
col = len;
}
g_status.buff_marker[n] = g_status.line_buff + col;
}
else {
/*
* work directly with main text
*/
if ((col = window->ccol) > (len = linelen(window->cursor))) {
col = len;
}
window->file_info->marker[n] = window->cursor + col;
}
}
/*
* Name: mark_start
* Purpose: To record the position of the start of the block in the file.
* Date: October 1, 1989
* Passed: window: information required to access current window
* Notes: This differs slightly from the setting of a normal mark,
* in that if we are using the current line buffer, the main
* text start marker must be modified also. (This may not
* still be necessary?)
*/
void mark_start(window)
windows *window;
{
int col; /* cursor column, or end of line, whichever is less */
int len; /* length of current line */
/*
* if the end of the block has already been marked, then the block
* must now become visible
*/
if (window->file_info->marker[END_BLOCK]) {
window->file_info->visible = TRUE;
}
if (g_status.copied) {
if ((col = window->ccol) > (len = linelen(g_status.line_buff))) {
col = len;
}
window->file_info->marker[START_BLOCK] = window->cursor;
g_status.buff_marker[START_BLOCK] = g_status.line_buff + col;
}
else {
if ((col = window->ccol) > (len = linelen(window->cursor))) {
col = len;
}
window->file_info->marker[START_BLOCK] = window->cursor + col;
}
}
/*
* Name: mark_end
* Purpose: To record the position of the end of the block in the file.
* Date: October 1, 1989
* Passed: window: information required to access current window
* Notes: This differs slightly from the setting of a normal mark,
* in that if we are using the current line buffer, the main
* text end marker must be modified also.
*/
void mark_end(window)
windows *window;
{
int col; /* cursor column, or end of line, whichever is less */
int len; /* length of current line */
if (window->file_info->marker[START_BLOCK]) {
window->file_info->visible = TRUE;
}
if (g_status.copied) {
if ((col = window->ccol) > (len = linelen(g_status.line_buff))) {
col = len;
}
window->file_info->marker[END_BLOCK] = window->cursor;
g_status.buff_marker[END_BLOCK] = g_status.line_buff + col;
}
else {
if ((col = window->ccol) > (len = linelen(window->cursor))) {
col = len;
}
window->file_info->marker[END_BLOCK] = window->cursor + col;
}
}
/*
* Name: prepare_block
* Purpose: To prepare a window/file for a block read, move or copy.
* Date: October 10, 1989
* Passed: window: information required to access current window
* Notes: The main complication is that the cursor may be beyond the end
* of the current line, in which case extra padding spaces have
* to be added before the block operation can take place.
*/
void prepare_block(window)
windows *window;
{
text_ptr source; /* source for block moves */
text_ptr dest; /* destination for block moves */
int pad; /* amount of padding to be added */
int len; /* length (usually of current line) */
int cr; /* does current line end with \n? */
long number; /* number of characters for block moves */
/*
* if cursor was beyond the end of the actual line, then add
* padding first.
*
* work on the current line buffer until padding is sorted out.
*/
copy_line(window);
if (window->ccol > (len = linelen(g_status.line_buff))) {
/*
* work out how much padding is required to extend the current
* line to the cursor position
*/
if (g_status.line_buff[len] == '\n') {
cr = 1;
}
else {
cr = 0;
}
pad = window->ccol - len;
/*
* check that there is room in the current line - should never
* give any problems...
*/
if (len + pad + cr >= BUFF_SIZE) {
error(WARNING, "too far right");
return;
}
/*
* make room for the padding spaces, and fix the markers
*/
source = g_status.line_buff + window->ccol - pad;
dest = source + pad;
number = len + pad - window->ccol + 1 + cr;
hw_move(dest, source, number);
fix_marks(window, source, (long) pad);
/*
* insert the padding spaces
*/
while (pad--) {
*source++ = ' ';
}
}
un_copy_line(window);
/*
* The cursor is now somewhere in the main text block, so there
* are no major complications.
*/
}
/*
* Name: move_block
* Purpose: To move the marked block from its current position to the
* cursor position.
* Date: October 1, 1989
* Passed: window: information required to access current window
*/
void block_move(window)
windows *window;
{
text_ptr source; /* source for block moves */
text_ptr dest; /* destination for block moves */
long number; /* number of characters for block moves */
int len; /* length (usually of current line) */
int add; /* characters being added from another line */
long block_len; /* length of the block */
text_ptr orig; /* cursor location in text */
text_ptr block_text; /* place block is temporarily moved to */
text_ptr block_dest; /* place block must finish up in */
text_ptr fix_pos; /* origin for marker fixup */
if (!window->file_info->visible) {